import 'package:flutter/services.dart';

class Printer {
  /// 打印单条指令
  /// @param mac    蓝牙打印机mac地址
  /// @param cmds   打印指令
  static void printCmd(String mac, String cmd) async {
    const platform = const MethodChannel("printer");
    try {
      Map<String, Object> param = {"mac": mac, "cmd": cmd};
      await platform.invokeMethod("printCmd", param);
    } on PlatformException catch (e) {
      print(e.message);
    }
  }

  /// 批量打印指令
  /// @param mac    蓝牙打印机mac地址
  /// @param cmds   打印指令
  static void printCmds(String mac, List<String> cmds) async {
    const platform = const MethodChannel("printer");
    try {
      Map<String, Object> param = {"mac": mac, "cmds": cmds};
      await platform.invokeMethod("printCmds", param);
    } on PlatformException catch (e) {
      print(e.message);
    }
  }
}
